Compiler Design


Q21.

The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and one destination operand. Assume that all variables are dead after this code segment. c = a + b; d = c * a; e = c + a; x = c * c; if (x > a) { y = a * a; } else { d = d * d; e = e * e; } What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocation
GateOverflow

Q22.

The program below uses six temporary variables a, b, c, d, e, f. a =1 b= 10 c =20 d= a +b e= c +d f =c +e b= c+ e e =b +f d =5 +e return d +f Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?
GateOverflow

Q23.

In a simplified computer the instructions are: The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block: Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?
GateOverflow

Q24.

Generation of intermediate code based on an abstract machine model is useful in compilers because
GateOverflow

Q25.

Mention the pass number for each of the following activities that occur in a two pass assembler: A. object code generation B. literals added to literal table C. listing printed D. address resolution of local symbols
GateOverflow

Q26.

Choose the correct alternatives (more than one may be correct) and write the corresponding letters only: Indicate all the true statements from the following:
GateOverflow

Q27.

The expression ( a * b) * c \; op \dots where 'op' is one of '+', '*' and '\uparrow' (exponentiation) can be evaluated on a CPU with single register without storing the value of (a * b) if
GateOverflow

Q28.

Some code optimizations are carried out on the intermediate code because
GateOverflow

Q29.

Consider the following statements. I. Symbol table is accessed only during lexical analysis and syntax analysis. II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment. III. Errors violating the condition 'any variable must be declared before its use' are detected during syntax analysis. Which of the above statements is/are TRUE?
GateOverflow

Q30.

A symbol table of length 152 is processing 25 entries at any instant. What is occupation density?
GateOverflow